<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%

request.setCharacterEncoding("utf-8");

String strAction = request.getParameter("action");
String strCatalogId = request.getParameter("catalogid");

String name = request.getParameter("catalogname");
String strclassid = request.getParameter("classid");
String hit = request.getParameter("hit");
String about = request.getParameter("editorValue");

/////判空操作////////////
if(null == name || "".equals(name)){
	out.println("标题不能为空");
}
//////////


com.zipishu.DataBaseConnection db = new com.zipishu.DataBaseConnection();
Connection con = db.getConnection();
String sql = "";

if("delete".equals(strAction)){
    sql = "DELETE FROM catelog WHERE catalogid=?";
	Integer catalogid = Integer.parseInt(strCatalogId);
	PreparedStatement pstmt = con.prepareStatement(sql);
	pstmt.setInt(1, catalogid);
	pstmt.executeUpdate();
}else{
	int classid = Integer.parseInt(strclassid);
	int hitr = Integer.parseInt(hit);
    if(null == strCatalogId || "".equals(strCatalogId)){
	    sql = "INSERT INTO catelog(catalogname,classid,hit,about,createdate) VALUES (?,?,?,?,getdate())";
	    PreparedStatement pstmt = con.prepareStatement(sql);
	    pstmt.setString(1, name);
		pstmt.setInt(2, classid);
		pstmt.setInt(3, hitr);
		pstmt.setString(4, about);
	    pstmt.executeUpdate();
	    }else{
	    Integer catalogid = Integer.parseInt(strCatalogId);
		sql = "UPDATE catelog SET catalogname=?,classid=?,hit=?,about=? WHERE catalogid=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, name);
		pstmt.setInt(2, classid);
		pstmt.setInt(3, hitr);
		pstmt.setString(4, about);			
		pstmt.setInt(5,catalogid);
	    pstmt.executeUpdate();
	    }
	}

con.close();

response.sendRedirect("item.jsp");

%>